//
//  ZFLMainViewController.m
//  iOSAppDevRepo_Example
//
//  Created by 翁胜琼 on 2019/2/12.
//  Copyright © 2019 折疯了. All rights reserved.
//

#import "ZFLMainViewController.h"
#import <WSQTabSelectionView.h>
#import <Masonry/Masonry.h>
#import <UIView+WSQBadge.h>
#import "ZFLCardsView.h"
#import "ZFLCardsViewCell.h"

static NSString* const REUSE_CELL_ID = @"ZFLCardsViewCell";
@interface ZFLMainViewController ()<ZFLCardsViewDelegate,ZFLCardsViewDataSource>

@property (nonatomic , strong) WSQTabSelectionView *tabSelectionView;
@property (strong,nonatomic) ZFLCardsView *cardsView;

@end

@implementation ZFLMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

// MARK: - ZFLCardsViewDelegate,ZFLCardsViewDataSource
- (NSInteger)numberOfCountInCardView:(ZFLCardsView *)cardView
{
    return 20;
}

- (ZFLCardsViewCell *)cardView:(ZFLCardsView *)cardView cellForRowAtIndex:(NSInteger)index
{
    ZFLCardsViewCell *cell = [cardView dequeueReusableCellWithIdentifier:REUSE_CELL_ID];
    cell.layer.cornerRadius = 10.0;
    cell.layer.masksToBounds = YES;
    return cell;
}

- (void)cardView:(ZFLCardsView *)cardView didRemoveLastCell:(ZFLCardsViewCell *)cell forRowAtIndex:(NSInteger)index
{
    [cardView reloadData];
}

- (void)setupUI
{
    [super setupUI];
    self.view.backgroundColor = UICOLORFROMHEXA(0x000000, 0.08);
    
    [self setupTabSelectionView];
    [self setupTestView];
    [self setupCardsView];
}

- (void)setupCardsView
{
    ZFLCardsView *view = [[ZFLCardsView alloc] initWithFrame:CGRectMake(25, 100, 315, 332)];
    view.backgroundColor = [UIColor lightGrayColor];//!< 为了指出carddView的区域，指明背景色
    view.dataSource = self;
    view.delegate = self;
    view.visibleCount = 3;
    view.lineSpacing = 15.0;
    view.interitemSpacing = 15.0;
    view.maxAngle = 10.0;
    view.isAlpha = YES;
    view.maxRemoveDistance = 100.0;
    view.layer.cornerRadius = 10.0;
//    view.der
    [view registerClass:[ZFLCardsViewCell class] forCellReuseIdentifier:REUSE_CELL_ID];
    [self.view addSubview:view];
}

- (void)setupTestView
{
    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 300)];
    testView.backgroundColor = green_color;
    
    [testView showBadgeWithTopPadding:-5 rightPadding:-11];
    testView.sq_badgeValue = @"99";
    testView.sq_badgeFontSize = 14;
    testView.sq_badgeBorderWidth = 1;
    testView.sq_badgeBorderColor = white_color;
    
    [self.view addSubview:testView];
}

- (void)setupTabSelectionView
{
    WSQTabSelectionView *tab = [[WSQTabSelectionView alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];
    tab.titles = @[ @"消息" , @"通知"];
    self.tabSelectionView = tab;
    tab.lineColor = red_color;
    tab.lineWidth = 18;
    tab.lineHeight = 4;
    tab.lineConfigurationBlock = ^CALayer *{
        CAGradientLayer *layer = [CAGradientLayer layer];
        layer.colors = @[(id)UICOLORFROMHEX(0x0DDDF6).CGColor,(id)UICOLORFROMHEX(0x1DEB96).CGColor];
        layer.startPoint = CGPointMake(0, 1);
        layer.endPoint = CGPointMake(1, 0);
        layer.locations = @[@(0),@(0.5)];
        return layer;
    };
    
    [tab setTitleFont:WSQFont18 forState:UIControlStateSelected];
    [tab setTitleFont:[UIFont fontWithName:@"PingFangSC-Bold" size:18] forState:UIControlStateNormal];
    
    [tab setTitleColor:UICOLORFROMHEX(0x010000) forState:UIControlStateSelected];
    [tab setTitleColor:UICOLORFROMHEX(0x7B7C7D) forState:UIControlStateNormal];
    
    self.navigationItem.titleView = tab;
    
    [tab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@120);
        make.height.equalTo(@30);
    }];
}

- (void)bindViewModel
{
    [super bindViewModel];
    
    @weakify(self);
    [self.tabSelectionView.tabClickedSub
     subscribeNext:^(id  _Nullable x) {
         
     }];
    
    [self.tabSelectionView.tabClickedSub sendNext:@0];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.view.frame = CGRectMake(0, Screen_NavBarHeight, Screen_Width, Screen_Height - Screen_NavBarHeight - Screen_TabBarHeight + 10);
}
@end
